<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div section {
            width: 100px;
            height: 100px;
            position: absolute;
            border:1px solid red ;
        }
        div section:nth-of-type(1) {
            background-color: sandybrown;
            display: block;
        }
        div section:nth-of-type(2) {
            background-color: sienna;
            display: none;
        }
        div section:nth-of-type(3) {
            background-color: springgreen;
            display: none;
        }
    </style>
</head>
<body>
    <div>
        <button>按钮1</button><button>按钮2</button><button>按钮3</button>
    </div>
    <div>
        <section>1</section>
        <section>2</section>
        <section>3</section>  
    </div>
    <script>
        let btns = document.querySelectorAll("div button");
        let secEles = document.querySelectorAll("div section");
        btns.forEach(function(btn,key){
            btn.onclick = function (){
                let index = key ; 
                secEles.forEach(function ( secEle , i ){
                    if ( index == i ){
                        secEle.style.display = "block" ;
                    } else {
                        secEle.style.display = "none" ; 
                    }
                });
            }
        });
    </script>
</body>
</html>